package com.cloudsdo.cameratest;

import android.app.Application;
import android.database.sqlite.SQLiteDatabase;

import com.cloudsdo.cameratest.dao.Student;
import com.cloudsdo.cameratest.database.DatabaseHelper;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;

import java.sql.SQLException;

/**
 * -----------------------------------------------------------------
 * Copyright (C) 2014-2016, by your company, All rights reserved.
 * -----------------------------------------------------------------
 * File: MyApp.java
 * Author: win7
 * Version: V100R001C01
 * Create: 2019/8/7 11:12
 * Changes (from 2019/8/7)
 * -----------------------------------------------------------------
 * 2019/8/7 : Create MyApp.java (win7);
 * -----------------------------------------------------------------
 */
public class MyApp extends Application{
    @Override
    public void onCreate() {
        super.onCreate();
        DatabaseHelper.setDbInfo("ai_db", 1, new DatabaseHelper.OnCreateListener() {
            @Override
            public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
                try {
                    TableUtils.createTable(connectionSource, Student.class);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
                try {
                    TableUtils.dropTable(connectionSource, Student.class, true);
                    onCreate(database, connectionSource);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
